package com.example.springbootdemo1.demos.web;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/login")
public class LoginController {
    @RequestMapping("/check")
    public  boolean check(String username, String password, HttpSession session){
        //检验密码和账号是否为空
        //if(username==null||"".equals(username)||password==null||"".equals(password)){
            //return false;
        //}
        if(!StringUtils.hasLength(username)||!StringUtils.hasLength(password)){
            return false;
        }
        //检验账号和密码是否正确模拟实现
        if("zhangsan".equals(username)&&"123456".equals(password)){
            session.setAttribute("username","username");
            return true;
        }
        return false;

    }
    @RequestMapping("/index")
    public String index(HttpSession session){
        String username = (String) session.getAttribute("username");
        return username;

    }
}
